<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\Progress;
use kartik\editable\Editable;
use yii\helpers\ArrayHelper;
use kartik\grid\GridView;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var common\models\search\GoodsSearch $searchModel
 */

$this->title                   = Yii::t('common', 'Goods');
$this->params['breadcrumbs'][] = $this->title;

?>


<?php
//             echo $this->render('_search', ['model' =>$searchModel]);
?>

<?= $columus = [
    [
        'class' => 'yii\grid\ActionColumn',

        'buttons'        => [
            'view' => function ($url, $model, $key) {
                $options = [
                    'title'      => Yii::t('cruds', 'View'),
                    'aria-label' => Yii::t('cruds', 'View'),
                    'data-pjax'  => '0',
                ];
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
            }
        ],
        'urlCreator'     => function ($action, $model, $key, $index) {
            // using the column name as key, not mapping to 'id' like the standard generator
            $params    = is_array($key) ? $key : [$model->primaryKey()[0] => (string)$key];
            $params[0] = \Yii::$app->controller->id ? \Yii::$app->controller->id . '/' . $action : $action;
            return Url::toRoute($params);
        },
        'contentOptions' => ['nowrap' => 'nowrap']
    ],

    [
         'mergeHeader'     => true,
        'attribute'       => 'goods_name',
        'class'           => 'kartik\grid\EditableColumn',
        'editableOptions' => [
            'inputType'   => Editable::INPUT_TEXT,

            'asPopover'   => false,
//            'formOptions' => [
//                'action' => Url::to(['input-update']),
//            ]
        ],

        'readonly'        => false,
    ],

    'gc_id',
    'gc_name',
    'spec_id',


    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:100px'],
        'class' => 'kartik\grid\EditableColumn',
        'attribute' => 'goods_image',
        'editableOptions' => [
            'formOptions' => [
                'action' => ['upload'],
            ],
            'preHeader' => '',

            'inputType' => Editable::INPUT_FILEINPUT,
            'options' => [
                'options' => ['accept' => '*'],
                'pluginOptions' => [
                    'showRemove' => false,
                    'showUpload' => false
                ]
            ],
        ],


//            'value'=>function($model){
//
//                $frontend = Yii::getAlias('@frontendUrl');
//                $images =\yii\helpers\Json::decode($model->file);
//                return $frontend.'/img/'.$images[0];
//            },
        'format'=>'raw'
    ],



    'goods_store_price',
    'goods_show',
    /*'goods_commend',*/

    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:300px'],
        'class' => 'kartik\grid\EditableColumn',
        'attribute' => 'goods_body',
        'editableOptions' => [
            'inputType' => Editable::INPUT_TEXTAREA,
            'size'=>'lg',
            'options' => ['class'=>'form-control', 'rows'=>5, 'placeholder'=>'Enter notes...']
        ],

    ],
    /*'brand_id',*/

    [
        'attribute' => 'type_id',
        'filterType' => GridView::FILTER_SELECT2,
        'filter' => [1 => '333', 2 => '4444'],

        'filterWidgetOptions' => [
            'pluginOptions' => ['allowClear' => true],
        ],
        'filterInputOptions' => ['placeholder' => Yii::t('app', 'please_select'), 'id' => 'grid-props-search-type_id']
    ],
    /*'spec_open',*/
    /*'goods_click',*/

    [

        'mergeHeader'     => true,
        'attribute'       => 'goods_state',
        'class'           => 'kartik\grid\EditableColumn',
        'editableOptions' => [
            'inputType'   => Editable::INPUT_SWITCH,
            'data'        => [2, 3],
            'asPopover'   => false,
            'formOptions' => [
                'action' => Url::to(['input-update']),
            ]
        ],
        'value'           => function ($model, $key) {
            $whether = \common\enums\WhetherEnum::map();
            return isset($whether[$model->info->real_buyer]) ? $whether[$model->info->real_buyer] : '';
        },
        'readonly'        => false,
    ],
    /*'goods_add_time:datetime',*/

    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:300px'],
        'attribute' => 'goods_starttime',
        'filterType'          => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]],
        'class' => 'kartik\grid\EditableColumn',
        'editableOptions' => [
            'inputType' => Editable::INPUT_DATE,
            'size'=>'lg',
            'options' => ['class'=>'form-control', 'rows'=>5, 'placeholder'=>'Enter notes...']
        ],
    ],
    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:300px'],
        'attribute' => 'goods_endtime',
        'filterType'          => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]],
        'class' => 'kartik\grid\EditableColumn',

        'editableOptions' => [
            'inputType' => Editable::INPUT_DATE,
            'size'=>'lg',
            'options' => ['class'=>'form-control', 'rows'=>5, 'placeholder'=>'Enter notes...']
        ],
    ],

     /*'goods_form',*/
    /*'transport_id',*/
    /*'commentnum',*/

    [
        'label'          => Yii::t('app/order', 'order_amount'),
        'contentOptions' => ['style' => 'min-width:180px;'],
        'mergeHeader'    => true,
        'attribute'      => 'salenum',
        'value'          => function ($model) {
            return Progress::widget([
                'percent'    => 60,
                'label'      => '60%',
                'barOptions' => ['class' => 'progress-bar-danger'],
                'options'    => ['class' => 'active progress-striped']
            ]);

        },
        'format'         => 'raw'
    ],
    /*'goods_collect',*/
    /*'goods_transfee_charge',*/
    /*'goods_image_more:ntext',*/


    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:100px'],
        'class' => 'kartik\grid\EditableColumn',
        'attribute' => 'goods_image',
        'editableOptions' => [
            'formOptions' => [
                'action' => ['upload'],
            ],
            'preHeader' => '',

            'inputType' => Editable::INPUT_FILEINPUT,
            'options' => [
                'options' => ['accept' => '*'],
                'pluginOptions' => [
                    'showRemove' => false,
                    'showUpload' => false
                ]
            ],
        ],
        'format'=>'raw'
    ],


    /*'goods_attr:ntext',*/
    /*'goods_spec:ntext',*/
    /*'goods_col_img:ntext',*/
    /*'spec_name',*/
    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:300px'],
        'class' => 'kartik\grid\EditableColumn',
        'attribute' => 'goods_keywords',
        'editableOptions' => [
            'inputType' => Editable::INPUT_TEXTAREA,
            'size'=>'lg',
            'options' => ['class'=>'form-control', 'rows'=>5, 'placeholder'=>'Enter notes...']
        ],

    ],
    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:300px'],
        'class' => 'kartik\grid\EditableColumn',
        'attribute' => 'goods_description',
        'editableOptions' => [
            'inputType' => Editable::INPUT_TEXTAREA,
            'size'=>'lg',
            'options' => ['class'=>'form-control', 'rows'=>5, 'placeholder'=>'Enter notes...']
        ],

    ],

    [
        'headerOptions' => ['class' => 'kv-sticky-column', 'style' => 'min-width:300px'],
        'class' => 'kartik\grid\EditableColumn',
        'attribute' => 'goods_close_reason',
        'editableOptions' => [
            'inputType' => Editable::INPUT_TEXTAREA,
            'size'=>'lg',
            'options' => ['class'=>'form-control', 'rows'=>5, 'placeholder'=>'Enter notes...']
        ],

    ],

    /*'goods_store_price_interval',*/
    /*'goods_serial',*/
];

echo \backend\widgets\GridWidget::widget(
    [
        'dataProvider' => $dataProvider,
        'gridColumns'  => $columus,
        'searchModel'  => $searchModel
    ]
);

?>







